package com.wits.av;

import android.util.Log;

/**
 * Created by zhengboyuan on 2018-08-27.
 */

public class JniRecordStore {

    public static final int    INVALID_HANDLE = -1;

    static {
        try {
            Log.i("jni", "loading JniRecordStore library");
            System.loadLibrary("RecordStore");
            Log.i("jni", "load JniRecordStore done");
        } catch (UnsatisfiedLinkError e) {
            Log.e("jni", "failed to load JniRecordStore");
        }
    }

    /**
     * 打开录像库
     * @param filepath  录像库路径
     * @return
     */
    public native static int recordstore_open(String filepath);

    /**
     * 关闭录像库
     * @param handle
     */
    public native static void recordstore_close(int handle);

    /**
     * 统计满足条件的录像数
     * @param query 查询条件
     * @return  录像数
     */
    public native static int recordstore_countRecord(MRecordQuery query);

    /**
     * 搜索录像
     * @param handle   句柄
     * @param query     查询
     * @param offset    偏移
     * @param records   录像结果, 需要预先分配
     * @return 录像个数
     */
    public native static int recordstore_findRecord(int handle, MRecordQuery query, int offset, MRecord[] records);

    /**
     * 删除录像
     * @param handle    句柄
     * @param id        录像标识
     * @return
     */
    public native static boolean recordstore_deleteRecord(int handle, int id);


    /**
     * 根据文件名删除录像
     * @param handle
     * @param filename  文件名
     * @return
     */
    public native static boolean recordstore_deleteRecordWithFileName(int handle, String filename);

    /**
     * 根据文件名查找录像
     * @param handle
     * @param filename  文件名
     * @param record    录像
     * @return
     */
    public native static boolean recordstore_findRecordWithFileName(int handle, String filename, MRecord record);

    /**
     * 清理破损的录像
     * @param handle
     */
    public native static void recordstore_clearBrokenRecord(int handle);


}
